home *** CD-ROM | disk | FTP | other *** search
/ Macworld Expo - Develope…Central & Net Innovations / Developer Central and Net Innovators (MacWorld Expo) (January 1999).iso / Developer Central / Bowers Development / Demo AppMaker / Examples / plain C OS8 / Everything / Radios.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-10-29  |  10.3 KB  |  436 lines  |  [TEXT/CWIE]

  1. /* Radios.c */
  2.  
  3. #include <Types.h>
  4. #include <Quickdraw.h>
  5. #include <Controls.h>
  6. #include <Dialogs.h>
  7. #include <Events.h>
  8. #include <Lists.h>
  9. #include <Menus.h>
  10. #include <Resources.h>
  11. #include <Sound.h>
  12. #include <TextEdit.h>
  13. #include <ToolUtils.h>
  14. #include <Appearance.h>
  15. #include <stdlib.h>
  16.  
  17. #include "Globals.h"
  18. #include "ResourceDefs.h"
  19. #include "DoScrap.h"
  20. #include "Miscellany.h"
  21. #include "Scrolling.h"
  22. #include "ControlUtils.h"
  23. #include "Dispatcher.h"
  24. #include "DDocData.h"
  25. #include "EverythingEngine.h"
  26. #include "EverythingDoc.h"
  27. #include "Radios.h"
  28.  
  29.  
  30. static    EverythingEngine*      GetEngine    (Radios*    self);
  31.  
  32. static    void    DoUndo        (Radios*    self);
  33. static    void    DoCut        (Radios*    self);
  34. static    void    DoCopy        (Radios*    self);
  35. static    void    DoPaste        (Radios*    self);
  36. static    void    DoClear        (Radios*    self);
  37. static    void    DoSelectAll        (Radios*    self);
  38. static    void    DoShowClipboard    (Radios*    self);
  39.  
  40.  
  41. //----------
  42. Radios*        NewRadios ()
  43. {
  44.     Radios*        window;
  45.  
  46.     window = (Radios*)malloc (sizeof (Radios));
  47.     Radios_Init (window);
  48.     SetClassID (window, classRadios);
  49.  
  50.     return window;
  51. }
  52.  
  53. //----------
  54. void    DeleteRadios (
  55.     Radios*        window)
  56. {
  57.     Radios_Free (window);
  58.     free (window);
  59. }
  60.  
  61. //----------
  62. void    Radios_Create (
  63.     AMDoc*            inDoc,
  64.     DDocData*        inData)
  65. {
  66.     Radios*        winObj = NewRadios ();
  67.  
  68.     if (winObj != nil) {
  69.         Radios_Open (winObj, inDoc, inData);
  70.     }
  71. }
  72.  
  73. //----------
  74. void    Radios_Init (
  75.     Radios*        self)
  76. {
  77. }
  78.  
  79. //----------
  80. void    Radios_Free (
  81.     Radios*        self)
  82. {
  83. }
  84.  
  85. //----------
  86. EverythingEngine*    GetEngine (
  87.     Radios*        self)
  88. {
  89.     return (EverythingEngine*) self->super.mDoc->mEngine;
  90. }
  91.  
  92. /*----------*/
  93. void    Radios_Open (
  94.     Radios*        self,
  95.     AMDoc*            inDoc,
  96.     DDocData*        inData)
  97. {
  98.     WindowPtr        window;
  99.     Handle            wftb;
  100.  
  101.     self->super.mDoc = inDoc;
  102.     self->mData = inData;
  103.     AddResponder ((AMSignaler*) self->mData, (AMResponder*) self);
  104.  
  105.     window = GetNewCWindow (WIND_Radios, nil, (WindowPtr) -1L);
  106.     if (AMEngine_GetFilename (self->super.mDoc->mEngine) [0] != 0) {
  107.         SetWTitle (window, AMEngine_GetFilename (self->super.mDoc->mEngine));
  108.     }
  109.     self->super.mWindow = window;
  110.     ((EverythingDoc*)self->super.mDoc)->mRadiosPtr = window;
  111.  
  112.     SetWindowKind (window, 'AM');
  113.     SetWRefCon (window, (long) self);
  114.     SetPort (window);
  115.     SetInfo (window);
  116.  
  117.     wftb = GetResource ('Wftb', WIND_Radios);
  118.  
  119.     CreateRootControl (window, &self->super.mRootControl);
  120.  
  121.     self->super.vScroll = nil;
  122.     self->super.hScroll = nil;
  123.  
  124.  
  125.     self->mRadioGroupGroupHandle = GetNewControl (CNTL_RadioGroupGroup, window);
  126.     self->mStandard3Handle = GetNewControl (CNTL_Standard3, window);
  127.     EmbedControl (self->mStandard3Handle, self->mRadioGroupGroupHandle);
  128.     SetWindowItemFont (self->mStandard3Handle, wftb, 2);
  129.  
  130.     self->mGroupBoxHandle = GetNewControl (CNTL_GroupBox, window);
  131.     SetWindowItemFont (self->mGroupBoxHandle, wftb, 3);
  132.     self->mGroupGroupHandle = GetNewControl (CNTL_GroupGroup, window);
  133.     EmbedControl (self->mGroupGroupHandle, self->mGroupBoxHandle);
  134.     self->mGroupRadio1Handle = GetNewControl (CNTL_GroupRadio1, window);
  135.     SetWindowItemFont (self->mGroupRadio1Handle, wftb, 5);
  136.     EmbedControl (self->mGroupRadio1Handle, self->mGroupGroupHandle);
  137.     self->mGroupRadio2Handle = GetNewControl (CNTL_GroupRadio2, window);
  138.     SetWindowItemFont (self->mGroupRadio2Handle, wftb, 6);
  139.     EmbedControl (self->mGroupRadio2Handle, self->mGroupGroupHandle);
  140.     self->mGroupRadio3Handle = GetNewControl (CNTL_GroupRadio3, window);
  141.     SetWindowItemFont (self->mGroupRadio3Handle, wftb, 7);
  142.     EmbedControl (self->mGroupRadio3Handle, self->mGroupGroupHandle);
  143.  
  144.     self->mGraphic3BoxHandle = GetNewControl (CNTL_Graphic3Box, window);
  145.     SetWindowItemFont (self->mGraphic3BoxHandle, wftb, 8);
  146.     self->mGraphic3GroupHandle = GetNewControl (CNTL_Graphic3Group, window);
  147.     EmbedControl (self->mGraphic3GroupHandle, self->mGraphic3BoxHandle);
  148.     self->mStopHandle = GetNewControl (CNTL_Stop, window);
  149.     EmbedControl (self->mStopHandle, self->mGraphic3GroupHandle);
  150.     SetWindowItemFont (self->mStopHandle, wftb, 10);
  151.     self->mGoHandle = GetNewControl (CNTL_Go, window);
  152.     EmbedControl (self->mGoHandle, self->mGraphic3GroupHandle);
  153.     SetWindowItemFont (self->mGoHandle, wftb, 11);
  154.  
  155.     self->mBevel3BoxHandle = GetNewControl (CNTL_Bevel3Box, window);
  156.     SetWindowItemFont (self->mBevel3BoxHandle, wftb, 12);
  157.     self->mBevel3GroupHandle = GetNewControl (CNTL_Bevel3Group, window);
  158.     EmbedControl (self->mBevel3GroupHandle, self->mBevel3BoxHandle);
  159.     self->mRadioButtonHandle = GetNewControl (CNTL_RadioButton, window);
  160.     EmbedControl (self->mRadioButtonHandle, self->mBevel3GroupHandle);
  161.     SetWindowItemFont (self->mRadioButtonHandle, wftb, 14);
  162.     SetBevelButtonGraphicAlignment (self->mRadioButtonHandle, kControlBevelButtonAlignCenter, 0, 0);
  163.     self->mRadioButton2Handle = GetNewControl (CNTL_RadioButton2, window);
  164.     EmbedControl (self->mRadioButton2Handle, self->mBevel3GroupHandle);
  165.     SetWindowItemFont (self->mRadioButton2Handle, wftb, 15);
  166.     SetBevelButtonGraphicAlignment (self->mRadioButton2Handle, kControlBevelButtonAlignCenter, 0, 0);
  167.  
  168.     self->mTextBoxHandle = GetNewControl (CNTL_TextBox, window);
  169.     SetWindowItemFont (self->mTextBoxHandle, wftb, 16);
  170.     self->mTextGroupHandle = GetNewControl (CNTL_TextGroup, window);
  171.     EmbedControl (self->mTextGroupHandle, self->mTextBoxHandle);
  172.     self->mNameHandle = GetNewControl (CNTL_Name, window);
  173.     EmbedControl (self->mNameHandle, self->mTextGroupHandle);
  174.     SetWindowItemFont (self->mNameHandle, wftb, 18);
  175.     self->mKindHandle = GetNewControl (CNTL_Kind, window);
  176.     EmbedControl (self->mKindHandle, self->mTextGroupHandle);
  177.     SetWindowItemFont (self->mKindHandle, wftb, 19);
  178.     self->mSizeHandle = GetNewControl (CNTL_Size, window);
  179.     EmbedControl (self->mSizeHandle, self->mTextGroupHandle);
  180.     SetWindowItemFont (self->mSizeHandle, wftb, 20);
  181.  
  182.     AdvanceKeyboardFocus (window);
  183.  
  184.     ShowWindow (window);
  185. }
  186.  
  187. /*----------*/
  188. void    Radios_Close (
  189.     Radios*        self)
  190. {
  191.     RemoveResponder ((AMSignaler*) self->mData, (AMResponder*) self);
  192.  
  193.     ((EverythingDoc*)self->super.mDoc)->mRadiosPtr = nil;
  194.     SetInfo (nil);
  195.     HideWindow (self->super.mWindow);
  196.     DisposeWindow (self->super.mWindow);
  197.  
  198.     DeleteRadios (self);
  199. }
  200.  
  201. /*----------*/
  202. void    Radios_Track (
  203.     Radios*        self,
  204.     ControlHandle    whichControl,
  205.     short            whichPart,
  206.     Point            where)
  207. {
  208.     Rect            bounds;
  209.     short            newValue;
  210.  
  211.     if (whichControl == self->mRadioGroupGroupHandle) {
  212.         if (TrackClick (whichControl, where) != 0) {
  213.             SetRadioGroup (self->mData, GetControlValue (self->mRadioGroupGroupHandle));
  214.         }
  215.     }
  216.     if (whichControl == self->mGroupGroupHandle) {
  217.         if (TrackClick (whichControl, where) != 0) {
  218.             SetGroup (self->mData, GetControlValue (self->mGroupGroupHandle));
  219.         }
  220.     }
  221.     if (whichControl == self->mGraphic3GroupHandle) {
  222.         if (TrackClick (whichControl, where) != 0) {
  223.             SetGraphic (self->mData, GetControlValue (self->mGraphic3GroupHandle));
  224.         }
  225.     }
  226.     if (whichControl == self->mBevel3GroupHandle) {
  227.         if (TrackClick (whichControl, where) != 0) {
  228.             SetBevel (self->mData, GetControlValue (self->mBevel3GroupHandle));
  229.         }
  230.     }
  231.     if (whichControl == self->mTextGroupHandle) {
  232.         if (TrackClick (whichControl, where) != 0) {
  233.             SetText (self->mData, GetControlValue (self->mTextGroupHandle));
  234.         }
  235.     }
  236. }
  237.  
  238. //----------
  239. void    Radios_DataChanged (
  240.     Radios*        self,
  241.     long            inDataID)
  242. {
  243.     if (inDataID == idRadioGroup) {
  244.         SetControlValue (self->mRadioGroupGroupHandle, GetRadioGroup (self->mData));
  245.     }
  246.     if (inDataID == idGroup) {
  247.         SetControlValue (self->mGroupGroupHandle, GetGroup (self->mData));
  248.     }
  249.     if (inDataID == idGraphic) {
  250.         SetControlValue (self->mGraphic3GroupHandle, GetGraphic (self->mData));
  251.     }
  252.     if (inDataID == idBevel) {
  253.         SetControlValue (self->mBevel3GroupHandle, GetBevel (self->mData));
  254.     }
  255.     if (inDataID == idText) {
  256.         SetControlValue (self->mTextGroupHandle, GetText (self->mData));
  257.     }
  258. }
  259.  
  260. /*----------*/
  261. void    Radios_MouseIn (
  262.     Radios*        self,
  263.     Point            where,
  264.     short            modifiers)
  265. {
  266.     Rect        bounds;
  267.  
  268. }
  269.  
  270. //----------
  271. void    Radios_ExitCurField (
  272.     Radios*        self)
  273. {
  274.     ControlHandle    focus;
  275.  
  276.     GetKeyboardFocus (self->super.mWindow, &focus);
  277.  
  278.     if (focus == nil) {
  279.         // nothing to exit
  280.  
  281.     }
  282. }
  283.  
  284. /*----------*/
  285. void    Radios_TypeIn (
  286.     Radios*        self,
  287.     char            ch)
  288. {
  289.     ControlHandle    focus;
  290.     short            keyCode;
  291.  
  292.     GetKeyboardFocus (self->super.mWindow, &focus);
  293.  
  294.     if ((ch == charEnter)
  295.     ||  (ch == charReturn)) {
  296.         Radios_ExitCurField (self);    // Dispatch
  297.     } else if (ch == charEsc) {
  298.     } else if (ch == charTab) {
  299.         AMWindow_DoTab ((AMWindow*) self, (curEvent.modifiers & optionKey) != 0);
  300.     } else if (focus != nil) {
  301.         keyCode = curEvent.message & keyCodeMask;
  302.         HandleControlKey (focus, keyCode, ch, curEvent.modifiers);
  303.         AMEngine_SetDirty (self->super.mDoc->mEngine);
  304.     } else {
  305.         SysBeep (1);
  306.     }
  307. }
  308.  
  309. /*----------*/
  310. void    Radios_Resize (
  311.     Radios*        self)
  312. {
  313.     /* application-specific code to resize items in window */
  314. }
  315.  
  316. /*----------*/
  317. void    Radios_Scroll (
  318.     Radios*        self,
  319.     short            newValue,
  320.     short            oldValue)
  321. {
  322.     /* application-specific code to scroll window */
  323.     if (gWhichScroll == self->super.vScroll) {
  324.     } else {    // horizontal
  325.     }
  326. }
  327.  
  328. //----------
  329. void    DoUndo (
  330.     Radios*        self)
  331. {
  332. } // DoUndo
  333.  
  334. //----------
  335. void    DoCut (
  336.     Radios*        self)
  337. {
  338.     TEHandle        curTE = AMWindow_GetCurTE ((AMWindow*) self);
  339.  
  340.     if (curTE != nil) {
  341.         TECut (curTE);
  342.         AMEngine_SetDirty (self->super.mDoc->mEngine);
  343.         scrapDirty = true;
  344.     }
  345. } // DoCut
  346.  
  347. //----------
  348. void    DoCopy (
  349.     Radios*        self)
  350. {
  351.     TEHandle        curTE = AMWindow_GetCurTE ((AMWindow*) self);
  352.  
  353.     if (curTE != nil) {
  354.         TECopy (curTE);
  355.         scrapDirty = true;
  356.     }
  357. } // DoCopy
  358.  
  359. //----------
  360. void    DoPaste (
  361.     Radios*        self)
  362. {
  363.     TEHandle        curTE = AMWindow_GetCurTE ((AMWindow*) self);
  364.  
  365.     if (curTE != nil) {
  366.         TEPaste (curTE);
  367.         AMEngine_SetDirty (self->super.mDoc->mEngine);
  368.     }
  369. } // DoPaste
  370.  
  371. //----------
  372. void    DoClear (
  373.     Radios*        self)
  374. {
  375.     TEHandle        curTE = AMWindow_GetCurTE ((AMWindow*) self);
  376.  
  377.     if (curTE != nil) {
  378.         TEDelete (curTE);
  379.         AMEngine_SetDirty (self->super.mDoc->mEngine);
  380.     }
  381. } // DoClear
  382.  
  383. //----------
  384. void    DoSelectAll (
  385.     Radios*        self)
  386. {
  387.     TEHandle        curTE = AMWindow_GetCurTE ((AMWindow*) self);
  388.  
  389.     if (curTE != nil) {
  390.         TESetSelect (0, 32767, curTE);
  391.     }
  392. } // DoSelectAll
  393.  
  394. //----------
  395. void    DoShowClipboard (
  396.     Radios*        self)
  397. {
  398. } // DoShowClipboard
  399.  
  400. //----------
  401. Boolean        Radios_DoCommand (
  402.     Radios*        self,
  403.     long            inCommand)
  404. {
  405.     Boolean        result = true;
  406.  
  407.     switch (inCommand) {
  408.         case cmdUndo:
  409.                 DoUndo (self);
  410.             break;
  411.         case cmdCut:
  412.                 DoCut (self);
  413.             break;
  414.         case cmdCopy:
  415.                 DoCopy (self);
  416.             break;
  417.         case cmdPaste:
  418.                 DoPaste (self);
  419.             break;
  420.         case cmdClear:
  421.                 DoClear (self);
  422.             break;
  423.         case cmdSelectAll:
  424.                 DoSelectAll (self);
  425.             break;
  426.         case cmdShowClipboard:
  427.                 DoShowClipboard (self);
  428.             break;
  429.  
  430.         default:
  431.                 result = false;
  432.     } // switch
  433.  
  434.     return result;
  435. }
  436.